		/*
		console.log(Dialog({
			title:"订单确认",
			content:"111"
		}).init());
		*/
var builder = require("mlib/layer/builder");
var compBase = require("mlib/comp/base");
var merge = require("mlib/json/merge");
var parseModule = require("mlib/dom/parseModule");
var touch = require("mlib/evt/touch");
var animationEnd = require("mlib/animation/animationEnd");
var dialogRender = require("../layer/dialog.ejs");



module.exports = function(opts,callback) {
	var that = compBase();
	var nodeList = null;
	var container = null;
	var m_dialog = null ;
	var mask = null;
        opts = merge({
            "title": "温馨提示",
			"cls":false,
            "OKText": "我知道了",
            "closeText":"X",
            "operates":[],
            "content":"",            
            "showClose":true,
            "showAnimate":true,
            "shadeClose":true,
			"isKeepMiddle":false,
            "OK": function() {}
        }, opts || {});
	
		m_dialog = builder.createFromHTML(dialogRender(opts), {
			"mask": true,
			"hideAnimate":function(dialog,hide){
				var container = dialog.getOuter();
					container.classList.add("slideout");
					animationEnd(container, "AnimationEnd", function () {
						hide();
					}, false);
			}
		});
    
		that.show = function(){		
			m_dialog.show({
				"afterAnimate":function(){
					that.fire("aftershow");
				}
			});
			
			container = m_dialog.getOuter();
			mask = m_dialog.getMask().getOuter();//that.getMask().getOuter();
			nodeList = parseModule(container);
		};

		m_dialog.bind("beforeshow",function(evt){
			var container = evt.target.getOuter();
			container.classList.add("slidein");
			animationEnd(container, "AnimationEnd", function () {
				container.classList.remove("slidein");
			}, false);
		});

		that.hide=function(){
			m_dialog.hide();
		};
		that.bind = function(){
				opts.operates.forEach(function(item,index){
					item.fn && touch.on(nodeList[item.name], "tap", function(evt){item["fn"].call(this,evt);});
				});
				nodeList.close && touch.on(nodeList.close, "tap", that.hide);
				
				if(opts.shadeClose){                
					touch.on(mask, "tap", that.hide);
				}
		};
		that.position = function(locate){
			switch(locate){
				case "center":
					m_dialog.setMiddle();
					break;
				case "bottom":
					m_dialog.setBottom();
					break;
			}
		}
		that.init = function(){
			that.show();
			that.position("bottom");
			that.bind();
		}
		return that;
}

